package com.itheima.d2_buffered_stream;

import java.io.*;

/**
 * 目标：掌握字节缓冲流的作用。
 */
public class Test1BufferedInputStream {
    public static void main(String[] args) throws FileNotFoundException {
        File file = new File("day10io-app2/file/file02.txt");
        File file1 = new File("day10io-app2/lib/file02.txt");
        copy(file, file1);

    }

    public static void copy(File src, File dest) throws FileNotFoundException {
       /* try (FileInputStream fis = new FileInputStream(src);
             FileOutputStream fos = new FileOutputStream(dest);) {

            int b;
            while ((b = fis.read()) != -1) {
                fos.write(b);
            }
        } catch (IOException e) {
            e.printStackTrace();

        }*/
        try(BufferedReader br = new BufferedReader(new FileReader(src));
            BufferedWriter bw = new BufferedWriter(new FileWriter(dest))
        ) {
            String b;
            while ((b = br.readLine()) != null) {
                bw.write(b);
                bw.newLine();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}